/* 
 * File:   LinearFilter.cpp
 * Author: amouro-m
 * 
 * Created on 5 juin 2010, 20:16
 */

#include "LinearFilter.h"
#include "tbb/tick_count.h"
#include <sstream>

LinearFilter::LinearFilter(Computable* computable, FractalPrinter* fp, ResultPanel* result_panel):
_fp(fp),
_computable(computable),
_result_panel(result_panel)
{}

LinearFilter::~LinearFilter() {}


void*
LinearFilter::compute ()
{
    tbb::tick_count start, end;
    start = tbb::tick_count::now();
    for (int i = 0; i < _fp->get_width(); ++i)
        for (int j = 0; j < _fp->get_height(); ++j)
            _computable->compute(_fp->get_area(), i, j);

    end = tbb::tick_count::now();
    tbb::tick_count::interval_t interval = (end - start);
    std::ostringstream os (std::ostringstream::out);
    os << _computable->print().toStdString() << ": " << interval.seconds() << " s";
    std::string string(os.str());

    _result_panel->add_item(string.c_str());

    _fp->repaint();
}